/*
 * Low-level routines to write the GDSII file.
 *
 * Copyright (c) 2010 Xaveer Leijtens
 *
 * This file is part of libMask.
 *
 * libMask is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * libMask is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with libMask.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef _LIBGDS_INCLUDED_
#define _LIBGDS_INCLUDED_
 
#include "mask.h"
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <limits>

/* Bit states for the STRANS Bit Array. */
#define GDS_BIT_REFLECT         0x8000
#define GDS_BIT_ABSMAGN         0x0004
#define GDS_BIT_ABSANGLE        0x0002

/* GDS Record types */
enum {
  GDS_REC_HEADER, GDS_REC_BGNLIB, GDS_REC_LIBNAME, GDS_REC_UNITS,
  GDS_REC_ENDLIB, GDS_REC_BGNSTR, GDS_REC_STRNAME, GDS_REC_ENDSTR,
  GDS_REC_BOUNDARY, GDS_REC_PATH, GDS_REC_SREF, GDS_REC_AREF, GDS_REC_TEXT,
  GDS_REC_LAYER, GDS_REC_DATATYPE, GDS_REC_WIDTH, GDS_REC_XY,
  GDS_REC_ENDEL, GDS_REC_SNAME, GDS_REC_COLROW, GDS_REC_TEXTNODE,
  GDS_REC_NODE, GDS_REC_TEXTTYPE, GDS_REC_PRESENTATION, GDS_REC_SPACING,
  GDS_REC_STRING, GDS_REC_STRANS, GDS_REC_MAG, GDS_REC_ANGLE,
  GDS_REC_UINTEGER, GDS_REC_USTRING, GDS_REC_REFLIBS, GDS_REC_FONTS,
  GDS_REC_PATHTYPE, GDS_REC_GENERATIONS, GDS_REC_ATTRTABLE,
  GDS_REC_STYPTABLE, GDS_REC_STRTYPE, GDS_REC_ELFLAGS, GDS_REC_ELKEY,
  GDS_REC_LINKTYPE, GDS_REC_LINKKEYS, GDS_REC_NODETYPE, GDS_REC_PROPATTR,
  GDS_REC_PROPVALUE, GDS_REC_BOX, GDS_REC_BOXTYPE, GDS_REC_PLEX,
  GDS_REC_BGNEXTN, GDS_REC_ENDEXTN, GDS_REC_TAPENUM, GDS_REC_TAPECODE,
  GDS_REC_STRCLASS, GDS_REC_RESERVED, GDS_REC_FORMAT, GDS_REC_MASK,
  GDS_REC_ENDMASKS, GDS_REC_LIBDIRSIZE, GDS_REC_SRFNAME, GDS_REC_LIBSECUR,
  GDS_REC_BORDER, GDS_REC_SOFTFENCE, GDS_REC_HARDFENCE, GDS_REC_SOFTWIRE,
  GDS_REC_HARDWIRE, GDS_REC_PATHPORT, GDS_REC_NODEPORT,
  GDS_REC_USERCONSTRAINT, GDS_REC_SPACER_ERROR, GDS_REC_CONTACT
};

/* GDS Value types */
enum {
  GDS_VAL_NODATA, GDS_VAL_BITARRAY, GDS_VAL_INT16, GDS_VAL_INT32,
  GDS_VAL_REAL4, GDS_VAL_REAL8, GDS_VAL_ASCII
};

/* Maximum length of a libname, excluding the terminating '\0' */
#define GDS_MAX_STRNAME      32

void gds_header();
void gds_bgnlib();
void gds_libname(const char *name);
void gds_units();
void gds_nodata(const uint8_t rec);
void gds_bgnstr();
void gds_strname(const char *name);
void gds_layer(const uint16_t lay);
void gds_width(const double w);
void gds_xy(size_t n, double *x, double *y, int);
void gds_sname(const char *name);
void gds_strans(const uint16_t bits);
void gds_mag(const double mag);
void gds_angle(const double ang);
void gds_datatype(int16_t type);
void gds_pathtype(int16_t type);
void gds_polyline(const size_t n, double *x, double *y, double w);
void gds_polygon(const size_t n, double *x, double *y);

#endif /* _LIBGDS_INCLUDED_ */
